<?php
	/**
	 * Arquivo: entidades/new_func.php
	 * @package Default
	 * @page-level 0
	 */
	session_start();
	require_once("../adm/ctpst.inc");
	$banco = new BANCOS();
	$forma = new FORMATAR();
	switch($_GET['acao']) 
		{
		case 1:
			{
			$sql = "select * from cadastro.funcionario where nome='".$_GET['nome']."'";
			$banco->exec_query($sql);
			if ($banco->num_registros > 0)
				{
				$dados = $banco->retorno[1][0];
				echo ("<label class=\"interna\">CPF:</label> <b>".$forma->cpf($dados[1])."</b>\n");
				echo ("<input type=\"hidden\" name=\"funcionario\" id=\"funcionario\" value=\"".$dados[0]."\" />\n");
				echo ("<label class=\"interna\">RG:</label> <b>".$dados[3]."</b>\n");
				echo ("<label class=\"interna\">Org. Exp.:</label> <b>".$dados[4]."</b>\n");
				}
			else 
				{
				echo ("<input type=\"hidden\" name=\"funcionario\" id=\"funcionario\" value=\"-1\" />\n");
				echo ("<b>CPF:</b><input type=\"text\" maxlength=\"14\" style=\"width:220px;\" size=\"40\" id=\"cpf\" name=\"cpf\" onkeypress=\"javascript:mascara(this,cpf_masc);\" maxlength=\"14\" />\n");
				echo ("<b>RG:</b><input type=\"text\" style=\"width:120px;\" size=\"40\" id=\"rg\" name=\"rg\" />\n");
				echo ("<b>Org. Exp.:</b><input type=\"text\" style=\"width:120px;\" size=\"40\" id=\"oexp\" name=\"oexp\" onkeypress=\"javascript:mascara(this,Maiusculos);\" />\n");
				//echo ("<input style=\"width:80px;\" type=\"button\" value=\"Salvar\" onclick=\"javascript:pegar('entidades/new_func.php?acao=2&nome='+document.getElementById('nome').value+'&cpf='+document.getElementById('cpf').value+'&rg='+document.getElementById('rg').value+'&oexp='+document.getElementById('oexp').value,escrever,'new_func','msg');\" />\n");
				echo ("<script type=\"text/javascript\" >\n");
				echo ("  <!--\n");
				echo ("    document.getElementById('cpf').focus();\n");
				echo ("  //-->\n");
				echo ("</script>\n");
				}
			break;
			}
		case 2:
			{
			//print_r($_GET);
			$sql = "insert into cadastro.funcionario (nome,cpf,rg,org_exp) values ('".$_GET['nome']."','".$forma->cpf($_GET['cpf'])."','".$_GET['rg']."','".$_GET['oexp']."')";
			$banco->exec_query($sql);
			$sql = "select id_fun from cadastro.funcionario where cpf='".$forma->cpf($_GET['cpf'])."'";
			$banco->exec_query($sql);
			$codigo = $banco->retorno[1][0][0];
			if ($banco->num_registros > 0)
				{
				$dados = $banco->retorno[1][0];
				echo ("<label class=\"interna\">Nome:</label> <b>".$_GET['nome']."</b>\n");
				echo ("<input type=\"hidden\" name=\"funcionario\" id=\"funcionario\" value=\"".$dados[0]."\" />\n");
				echo ("<label class=\"interna\">RG:</label> <b>".$_GET['rg']."</b>\n");
				echo ("<label class=\"interna\">Org. Exp.:</label> <b>".$_GET['oexp']."</b>\n");
				}
			break;
			}
		}
?>